﻿namespace Chain.BLL
{
    using Chain.DAL;
    using Chain.Model;
    using System;
    using System.Collections.Generic;
    using System.Data;

    public class WeiXinNews
    {
        private readonly Chain.DAL.WeiXinNews dal = new Chain.DAL.WeiXinNews();

        public int Add(Chain.Model.WeiXinNews model)
        {
            return this.dal.Add(model);
        }

        public List<Chain.Model.WeiXinNews> DataTableToList(DataTable dt)
        {
            List<Chain.Model.WeiXinNews> list = new List<Chain.Model.WeiXinNews>();
            int count = dt.Rows.Count;
            if (count > 0)
            {
                for (int i = 0; i < count; i++)
                {
                    Chain.Model.WeiXinNews item = new Chain.Model.WeiXinNews();
                    if ((dt.Rows[i]["NewsID"] != null) && (dt.Rows[i]["NewsID"].ToString() != ""))
                    {
                        item.NewsID = int.Parse(dt.Rows[i]["NewsID"].ToString());
                    }
                    if ((dt.Rows[i]["NewsRuleID"] != null) && (dt.Rows[i]["NewsRuleID"].ToString() != ""))
                    {
                        item.NewsRuleID = int.Parse(dt.Rows[i]["NewsRuleID"].ToString());
                    }
                    if ((dt.Rows[i]["NewsTitle"] != null) && (dt.Rows[i]["NewsTitle"].ToString() != ""))
                    {
                        item.NewsTitle = dt.Rows[i]["NewsTitle"].ToString();
                    }
                    if ((dt.Rows[i]["NewsDesc"] != null) && (dt.Rows[i]["NewsDesc"].ToString() != ""))
                    {
                        item.NewsDesc = dt.Rows[i]["NewsDesc"].ToString();
                    }
                    if ((dt.Rows[i]["NewsUrlFirst"] != null) && (dt.Rows[i]["NewsUrlFirst"].ToString() != ""))
                    {
                        item.NewsUrlFirst = dt.Rows[i]["NewsUrlFirst"].ToString();
                    }
                    if ((dt.Rows[i]["NewsUrlSecond"] != null) && (dt.Rows[i]["NewsUrlSecond"].ToString() != ""))
                    {
                        item.NewsUrlSecond = dt.Rows[i]["NewsUrlSecond"].ToString();
                    }
                    if ((dt.Rows[i]["NewsLinkContent"] != null) && (dt.Rows[i]["NewsLinkContent"].ToString() != ""))
                    {
                        item.NewsLinkContent = dt.Rows[i]["NewsLinkContent"].ToString();
                    }
                    if ((dt.Rows[i]["NewsCreateTime"] != null) && (dt.Rows[i]["NewsCreateTime"].ToString() != ""))
                    {
                        item.NewsCreateTime = DateTime.Parse(dt.Rows[i]["NewsCreateTime"].ToString());
                    }
                    list.Add(item);
                }
            }
            return list;
        }

        public bool Delete(int NewsID)
        {
            return this.dal.Delete(NewsID);
        }

        public bool DeleteList(string NewsIDlist)
        {
            return this.dal.DeleteList(NewsIDlist);
        }

        public bool Exists(int NewsID)
        {
            return this.dal.Exists(NewsID);
        }

        public DataSet GetAllList()
        {
            return this.GetList("");
        }

        public DataSet GetList(string strWhere)
        {
            return this.dal.GetList(strWhere);
        }

        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return this.dal.GetList(Top, strWhere, filedOrder);
        }

        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return this.dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }

        public int GetMaxId()
        {
            return this.dal.GetMaxId();
        }

        public Chain.Model.WeiXinNews GetModel(int NewsID)
        {
            return this.dal.GetModel(NewsID);
        }

        public List<Chain.Model.WeiXinNews> GetModelList(string strWhere)
        {
            DataSet list = this.dal.GetList(strWhere);
            return this.DataTableToList(list.Tables[0]);
        }

        public DataTable GetParent()
        {
            return this.dal.GetParent();
        }

        public int GetRecordCount(string strWhere)
        {
            return this.dal.GetRecordCount(strWhere);
        }

        public bool Update(Chain.Model.WeiXinNews model)
        {
            return this.dal.Update(model);
        }
    }
}

